package com.sqllog.admin.auth.controller;


import com.sqllog.admin.auth.domain.Menu;
import com.sqllog.admin.auth.domain.User;
import com.sqllog.admin.auth.service.MenuService;
import com.sqllog.admin.framework.tools.SecurityUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * 获取用户对应的菜单
 *
 * @author chennengcheng
 * @date 2022-01-21 17:02
 * @remark
 */

@RestController
@RequestMapping(SysMenuController.API_SYSTEM_PREFIX + "menu/")
public class SysMenuController {
    /**
     * 系统业务基础路径
     */
    public final static String API_SYSTEM_PREFIX = "/system/";

    @Resource
    private MenuService menuService;

    /**
     * Describe: 根据 username 获取菜单数据
     * Param SysRole
     * Return 执行结果
     */
    @GetMapping("/data")
    public List<Menu> getUserMenu() {
        User sysUser = SecurityUtil.currentUser();
        List<Menu> menus = menuService.getUserMenu(sysUser.getUsername());
        return menuService.toUserMenu(menus, "0");
    }
}
